
 
use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

	
	merge m:1 postcode using Data/AboveBelowRoof.dta

	drop _merge

	merge m:1 postcode using Data/Postcode_matching.dta

	drop _merge 

		
	
	merge m:1 postcode using Data/SA3postcode.dta
	drop _merge
	merge m:1 SA3_CODE16 using "data/maps/sa3" 

	keep if _merge ==3
	drop _merge
	*  melbourne

	gen Melbourne = 1 if SA4_CODE=="213" | SA4_CODE =="210" | SA4_CODE=="209" | SA4_CODE =="207" | SA4_CODE=="211"  | SA4_CODE=="208" | 	SA4_CODE=="206" | SA4_CODE=="212"
	replace Melbourne =0 if Melbourne ==.		
				

	keep if Melbourne ==1
			
			forvalues y = 2009(1)2015 { 
						forval q = 1(1)5{ 

			gen quin_year`y'_`q' = (year==`y')*(quintiles_Relative==`q')  
						}
			gen distance_year`y' = GPO_distance * (year==`y')
 			gen above_med_`y' = (above_medRelative==2) * (year==`y')

			
					}
				
				
		
 

	xi: xtivreg2 green_p (cum = roofrelativeIV)   i.quarter  [aweight =NCustomers	] if  Melbourne ==1 , fe cluster(postcode) first 
 
 
 
	quietly summ green_plan [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)

	outreg2 using Analysis/MelbInnerMiddleOuter, bdec(3) label ctitle("All Suburbs")  addstat(CDW F-test, e(widstat)) ///
	keep(cum median_*)  addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes replace
 
 
 
 
	xi: xtivreg2 green_p (cum = roofrelativeIV)   i.quarter  [aweight =NCustomers	] if GPO_distance <=5 & Melbourne ==1 , fe cluster(postcode) first 
 
 
 
 
	quietly summ green_plan [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)

	outreg2 using Analysis/MelbInnerMiddleOuter, bdec(3) label ctitle("Inner Suburbs")  addstat(CDW F-test, e(widstat)) ///
	keep(cum median_*)  addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
 
 
 
 
 
 
	xi: xtivreg2 green_p (cum = roofrelativeIV)   i.quarter  [aweight =NCustomers	] if GPO_distance >5 & GPO_distance <= 20  & Melbourne ==1 , fe cluster(postcode) first 
 
 
 
 
 
	quietly summ green_plan [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)

	outreg2 using Analysis/MelbInnerMiddleOuter, bdec(3) label ctitle("Middle Suburbs")  addstat(CDW F-test, e(widstat)) ///
	keep(cum median_*)  addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
 
 
 
 
 
	xi: xtivreg2 green_p (cum = roofrelativeIV)   i.quarter  [aweight =NCustomers	] if GPO_distance >= 20   & Melbourne ==1 , fe cluster(postcode) first 
 

 
 
 
	quietly summ green_plan [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)
	
	
	

	outreg2 using Analysis/MelbInnerMiddleOuter, bdec(3) label ctitle("Outer Suburbs")  addstat(CDW F-test, e(widstat)) ///
	keep(cum median_*)  addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
 
 
 
 
 
 
 
 
 
	summ cum [aweight =NCustomers	] if  GPO_distance <= 5 & Melbourne ==1
    local meanindvar=round(`r(mean)',.001)

	
	
	summ cum [aweight =NCustomers	] if GPO_distance > 5 & GPO_distance< 20 & Melbourne ==1
    local meanindvar=round(`r(mean)',.001)

	
	
 
	summ cum [aweight =NCustomers	] if GPO_distance >= 20 & Melbourne ==1
    local meanindvar=round(`r(mean)',.001)

 
	
 
